from django.db import models

# Create your models here.
from django.db.models import CASCADE, PROTECT, DO_NOTHING


class CMS_COLLEGE(models.Model):
    ID = models.AutoField(primary_key=True)
    COLLEGE_NAME = models.CharField(max_length= 20,default=None,unique=True,)
    CREATED_TIME = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.COLLEGE_NAME

    class Meta:
        verbose_name = '基本表 学校'
        verbose_name_plural = verbose_name


class CMS_ORG(models.Model):
    ID = models.AutoField(primary_key=True)
    SCHOOL_ID = models.ForeignKey('CMS_COLLEGE',on_delete=CASCADE,related_name='college_org')
    NAME = models.CharField(max_length= 20,blank=True,default=None,unique=True,null=True)
    REMARK = models.CharField(max_length= 200,blank=True,default=None,unique=True,null=True)
    LEVEL = models.IntegerField()
    LEADER = models.CharField(max_length= 20,blank=True,default=None,unique=True,null=True)
    def __str__(self):
        return self.NAME

    class Meta:
        verbose_name = '部门机构'
        verbose_name_plural = verbose_name


class USER_ROLE(models.Model):
    ID = models.AutoField(primary_key=True)
    ORG_ID = models.ForeignKey('CMS_ORG',on_delete=CASCADE)
    STUDENT_ID = models.ForeignKey('CMS_STUDENT',on_delete=CASCADE)
    UPDATED_TIME = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return str(self.STUDENT_ID)

    class Meta:
        verbose_name = '职责分工表'
        verbose_name_plural = verbose_name


class CMS_STUDENT(models.Model):
    ID = models.AutoField(primary_key=True)
    CLASS_ID = models.ForeignKey('CMS_CLASS',on_delete=PROTECT)
    ORG_ID = models.ManyToManyField('CMS_ORG',default=None,blank=True,related_name='student_org')
    USERNAME = models.CharField(max_length= 20,blank=True,default=None,unique=True,null=True)
    PASSWORD = models.IntegerField(null=False,blank=False)
    TOKEN = models.IntegerField(null=True,blank=True,default=None)
    TOKEN_ADD_TIME = models.DateTimeField(auto_now_add=True)
    # ID_CORD_NUM = models.IntegerField(null=False,blank=False)
    # UPDATED_TIME = models
    # MOBILE_PHONE = models
    # IPONE_FIRST = models
    # IPONE_SECOND = models

    def __str__(self):
        return self.USERNAME

    class Meta:
        verbose_name = '主表 学生信息'
        verbose_name_plural = verbose_name


class CMS_CLASS(models.Model):
    ID = models.AutoField(primary_key=True)
    GREAD_ID = models.ForeignKey('CMS_GREAD', on_delete=PROTECT)
    CLASS_NUM = models.IntegerField()
    def __str__(self):
        return f'{self.GREAD_ID}年级({self.CLASS_NUM})班'

    class Meta:
        verbose_name = '基本表 班级,格式1 2 3 4'
        verbose_name_plural = verbose_name


class CMS_GREAD(models.Model):
    ID = models.AutoField(primary_key=True)
    GREAD_NUM = models.IntegerField()
    def __str__(self):
        return str(self.GREAD_NUM)

    class Meta:
        verbose_name = '基本表年级(格式2019)'
        verbose_name_plural = verbose_name


class CMS_SCORE(models.Model):
    ID = models.AutoField(primary_key=True)
    STUDENT_ID = models.ForeignKey('CMS_STUDENT', on_delete=CASCADE)
    SCORESTYLE_ID = models.ForeignKey('CMS_SCORESTYLE', on_delete=CASCADE)
    SCORE = models.IntegerField()
    UPDATED_BY = models.ForeignKey('CMS_ORG', on_delete=CASCADE)
    UPDATED_TIME = models.DateTimeField(auto_now_add=True)
    def __str__(self):
        return f'{self.STUDENT_ID} 积分变动情况'

    class Meta:
        verbose_name = '积分变动表'
        verbose_name_plural = verbose_name


class CMS_SCORESTYLE(models.Model):
    ID = models.AutoField(primary_key=True)
    ADD_SCORE_STYLE = models.CharField(max_length= 100,blank=True,default=None,null=True)
    SCORE_NUM = models.IntegerField()
    def __str__(self):
        return f'积分变动原因:{self.ADD_SCORE_STYLE} , 分值变动:{self.SCORE_NUM}'

    class Meta:
        verbose_name = '积分变动类型表'
        verbose_name_plural = verbose_name


